import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
class TestOA:
    @pytest.fixture()
    def get_driver(self):
        driver = webdriver.Chrome()
        driver.implicitly_wait(10)
        driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
        driver.maximize_window()
        driver.find_element(By.ID, "account").send_keys("123456")
        driver.find_element(By.ID, "password").send_keys("123456")
        driver.find_element(By.ID, "submit").click()
        driver.find_element(By.XPATH, "/html/body/div[1]/div[1]/div/ul[1]/li[2]/button/img").click()
        driver.switch_to.frame("iframe-1")
        driver.find_element(By.XPATH, "/html/body/div[2]/div[1]/a").click()
        yield driver
        driver.quit()
    testdata = [
                ("78543","gg","指派"),
                ("123","","联系人不能为空。"),
               ]
    @pytest.mark.parametrize("title,contact,expect",testdata)
    def test_login(self,get_driver,title,contact,expect):
      try:
        driver = get_driver
        sleep(2)
        driver.find_element(By.ID,"name").send_keys(title)
        sleep(2)
        driver.find_element(By.ID,"contact").send_keys(contact)
        sleep(2)
        driver.find_element(By.ID,"submit").click()
        sleep(2)
        if expect == "指派":
            text = driver.find_element(By.LINK_TEXT, "指派").text
            assert text == expect, "保存失败"
        else:
            message = driver.find_element(By.XPATH, "/html/body/div/div[1]/div[2]/form/table/tbody/tr[2]/td/span").text
            assert message == expect, "保存失败"
      except AssertionError as e:
        raise e
      except Exception as e:
        print(e)
        raise e
